package com.yixin.vuehr.service;

import com.yixin.vuehr.model.Hr;
import com.yixin.vuehr.util.HrUtils;
import com.yixin.vuehr.mapper.AccountMapper;
import com.yixin.vuehr.model.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class AccountService {
    @Autowired
    AccountMapper accountMapper;
    public List<Account> getAllAccount() {
        return accountMapper.selectAll(HrUtils.getCurrentHr().getId());
    }

    public Integer addAccount(Account account) {
        Hr currentHr = HrUtils.getCurrentHr();
        String username = currentHr.getUsername();
        account.setHrid(currentHr.getId());
        account.setCreatedBy(username);
        account.setCreatedDate(new Date());
        account.setUpdatedBy(username);
        account.setUpdatedDate(new Date());
        return accountMapper.insertSelective(account);
    }

    public Integer deleteAccount(Integer id) {
        return accountMapper.deleteAccountById(id);
    }

    public Integer updateAccount(Account account) {
        account.setUpdatedDate(new Date());
        return accountMapper.updateByPrimaryKeySelective(account);
    }
}
